//
//  Kanbox_TrendsViewController.m
//  fxxiaoke
//
//  Created by 鞠超 on 2016/10/14.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "Kanbox_TrendsViewController.h"

#import "Kanbox_TrendsTableViewCell.h"
#import "Kanbox_TrendDetailViewController.h"
#import "Kanbox_TrendDetailViewController_1.h"

@interface Kanbox_TrendsViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView * tableView;

@end

@implementation Kanbox_TrendsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void )p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    
    _lblTitle.text = @"网盘动态";
    _topView.backgroundColor = navi_bar_bg_color;
    
    //左返回
    UIImageView * image_LeftRetrun = [[UIImageView alloc] initWithFrame:CGRectMake(11, 31.5, 25, 25)];
    image_LeftRetrun.userInteractionEnabled = YES;
    image_LeftRetrun.image = [UIImage imageNamed:@"Left-return.png"];
    [_topView addSubview:image_LeftRetrun];
    
    UILabel * lbl_return = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_LeftRetrun.frame) - 6, 35, 65, 15)];
    lbl_return.text = @"XX网盘";
    lbl_return.textColor = [UIColor whiteColor];
    lbl_return.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:lbl_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(10, 22, 90, 40);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//显示tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [[UIView alloc] init];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.tableView];
    
    //注册
    [self.tableView registerClass:[Kanbox_TrendsTableViewCell class] forCellReuseIdentifier:@"cell_Trends"];
}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Kanbox_TrendsTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell_Trends" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.btn_bg.tag = 1000 * indexPath.section + indexPath.row;
    [cell.btn_bg addTarget:self action:@selector(btn_bgAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView * view_bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 35)];
    view_bg.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    //
    UILabel * lbl_date = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, SCREEN_WIDTH - 30, 15)];
    lbl_date.text = [NSString stringWithFormat:@"2016-%02ld-21 星期一",section + 1];
    lbl_date.textColor = [UIColor blackColor];
    lbl_date.font = [UIFont systemFontOfSize:15.0f];
    [view_bg addSubview:lbl_date];
    
    //
    UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(0, 33, SCREEN_WIDTH, 2)];
    view_Line.backgroundColor = [UIColor colorWithRed:222/255.0 green:222/255.0 blue:224/255.0 alpha:1.0f];
    [view_bg addSubview:view_Line];
    
    return view_bg;
}

- (CGFloat )tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 35;
}

#pragma mark - 点击进入照片或pdf
- (void )btn_bgAction:(UIButton *)sender
{
    NSInteger length_cols = sender.tag / 1000;
    NSInteger length_rows = sender.tag % 1000;
    NSLog(@"%ld-------------%ld",length_cols,length_rows);
    
    NSLog(@"点击进入照片或pdf");
    
//    //点击进入照片
//    Kanbox_TrendDetailViewController * kanbox_TrendDetailViewController = [[Kanbox_TrendDetailViewController alloc] init];
//    [self showViewController:kanbox_TrendDetailViewController sender:nil];

    
    //点击pdf
    Kanbox_TrendDetailViewController_1 * kanbox_TrendDetailViewController_1 = [[Kanbox_TrendDetailViewController_1 alloc] init];
    kanbox_TrendDetailViewController_1.str_title = @"文档名称";
    [self showViewController:kanbox_TrendDetailViewController_1 sender:nil];
}










@end
